package io.xxx.omni.oss.domain

import com.baomidou.mybatisplus.annotation.TableId
import java.time.LocalDateTime

data class Document(
    @TableId
    var id: Long?,
    var storeId: String?,
    var sn: String?,
    var rsn: String?,
    var status: String?,
    var data: String?,
    var state: Int?,
    var created: LocalDateTime?,
    var modified: LocalDateTime?,
    var fetchedCreated: LocalDateTime?,
    var fetchedModified: LocalDateTime?,
) {
    constructor() : this(null, null, null, null, null, null, null, null, null, null, null)

    constructor(
        sn: String,
        status: String,
        data: String,
        created: LocalDateTime,
        modified: LocalDateTime,
    ) : this(null, null, sn, null, status, data, 1, created, modified, null, null)

    constructor(
        sn: String,
        rsn: String,
        status: String,
        data: String,
        created: LocalDateTime,
        modified: LocalDateTime,
    ) : this(null, null, sn, rsn, status, data, 1, created, modified, null, null)

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class.java != other::class.java) return false
        other as Document
        return storeId == other.storeId && sn == other.sn
    }

    override fun hashCode(): Int = 1422296640

    operator fun compareTo(other: Document): Int {
        return modified?.compareTo(other.modified) ?: 1
    }
}